home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / COMMON.ZIP / GFILE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-31  |  2.0 KB  |  81 lines

  1. /* sort stuff */
  2. static char **gb_sort_array;
  3.  
  4. static char **gb_t1;
  5. static char **gb_t2;
  6.  
  7.  
  8. /* case sensitive sort */
  9. /* ----------------- compare_ascii2() ------------------ Januaray 3, 1991 */
  10. int compare_ascii2(const void *t1, const void *t2)
  11. {
  12.  
  13.    gb_t1=(char **)t1;
  14.    gb_t2=(char **)t2;
  15.  
  16.    return(strcmp(*gb_t1, *gb_t2));
  17. }
  18.  
  19. // used to sort the file names
  20. /* ---------------------- str_array_sort() ------------- January 31,1992 */
  21. void str_array_sort(char **array, int max)
  22. {
  23.     if ( max > 1 )
  24.         {
  25.         gb_sort_array=array;
  26.         qsort(gb_sort_array, max, sizeof(char *), compare_ascii2);
  27.         }
  28.  
  29. }
  30.  
  31.  
  32. /* ----------------------- get_files() --------------------- April 9,1991 */
  33. int get_files(char *f_names[], char *file_mask, int attr)
  34. {
  35.    int number_of_files;
  36.    char path[100];
  37.    struct ffblk fb;
  38.  
  39.  
  40.    getcwd(path, 90);
  41.    if ( *(path+strlen(path)-1) != '\\' )
  42.       strcat(path, "\\");
  43.    strcat(path, file_mask);
  44.  
  45.    memset((char *)&fb, 0, sizeof(fb));
  46.    number_of_files=0;
  47.    if ( !findfirst(path, &fb, attr) )
  48.       {
  49.       if ( !attr || fb.ff_attrib == attr )
  50.          {
  51.          if ( f_names[number_of_files] == NULL )
  52.             f_names[number_of_files]=(char *)malloc(16);
  53.          strcpy(f_names[number_of_files], fb.ff_name);
  54.          ++number_of_files;
  55.          }
  56.  
  57.       while ( !findnext(&fb) )
  58.          {
  59.          if ( !attr || fb.ff_attrib == attr )
  60.             {
  61.             if ( f_names[number_of_files] == NULL )
  62.                {
  63.                f_names[number_of_files]=(char *)malloc(16);
  64.                if ( f_names[number_of_files] == NULL )
  65.                   {
  66.                   printf("\nout of mem coreleft() %u n %d\n", coreleft(), number_of_files);
  67.                   exit(1);
  68.                   }
  69.                }
  70.             strcpy(f_names[number_of_files], fb.ff_name);
  71.             ++number_of_files;
  72.             }
  73.          }
  74.       }
  75.  
  76.    // sort
  77.    str_array_sort(f_names, number_of_files); 
  78.  
  79.    return(number_of_files);
  80. }
  81.